﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;

namespace IHISCETeim.Web.MachineSys.PartsModel
{
    public partial class PartsBalanceAdd : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "PartsCatheringList";
            }
        }

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.修改 };
            }
        }

        protected int CId
        {
            get
            {
                return GetRequestValue<int>("cid", 0);
            }
        }

        protected PartsCatheringInfo _objShow = null;
        protected PartsCatheringInfo objShow
        {
            get
            {
                if (_objShow == null)
                    _objShow = PartsCatheringController.GetList(CId);

                return _objShow;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();

            }
        }
        private void addmenu()
        {
            char[] caSplit = new char[] { ',' };
            string[] DebtIdS = GetRequestValue<string>("DebtId", "").Split(caSplit);
            string[] BalanceMoneys = GetRequestValue<string>("BalanceMoney", "").Split(caSplit);
            string[] CreateDates = GetRequestValue<string>("CreateDate", "").Split(caSplit);


            List<PartsBalanceInfo> list = new List<PartsBalanceInfo>();
            for (int rowIndex = 0; rowIndex < DebtIdS.Count(); rowIndex++)
            {


                PartsBalanceInfo itm = new PartsBalanceInfo();
                itm.Cid = CId;
                itm.DebtId = Convert.ToInt32(DebtIdS[rowIndex]);
                itm.BalanceMoney = Convert.ToDecimal(BalanceMoneys[rowIndex]);
              
                itm.RealName = base.User.RealName;
                itm.CreateDate = Convert.ToDateTime(CreateDates[rowIndex]);
                itm.Remark = "";
             
                list.Add(itm);
            }

          


            int msg = PartsBalanceController.Add(list);

            switch (msg)
            {
                case -1:
                    ErrorJson("冲帐失败.余额不足，请确认再操作.");
                    break;
                case -99:
                    ErrorJson("冲帐失败.未知错误");
                    break;
                default:
                    SuccessJson("已成功冲帐","");
                    break;
            }            

        }
    }
}